package com.xxx.corejava.day1104;

import java.util.Arrays;

public class Test4 {

    public static void main(String[] args) {

        //栈里面定义int[]类型的变量arr
        int[] arr;
        //int a[];

        /*
            1.堆分配空间
            2.初始化
            3.将空间的首地址赋值给arr
         */
        arr=new int[4];

        System.out.println("arr = " + arr);

        System.out.println("arr[2] = " + arr[2]);

        arr[1]=5;

        System.out.println("arr[1] = " + arr[1]);

        //数组的静态初始化
        int[] arr2=new int[]{1,34,6,123,77,234};

        System.out.println("arr2 = " + arr2);

        System.out.println("arr2.length = " + arr2.length);

        for (int i = 0; i < arr2.length; i++) {
            System.out.println(arr2[i]);
        }

        //数组下标越界异常，不能访问
        //System.out.println(arr2[6]);


        int[] arr3={23,5435,123,666};
        System.out.println("arr3 = " + Arrays.toString(arr3));

        //错，{}只能做静态初始化不能修改值
        //arr3={1,2,3,4};

        //相当于创建了一个新的数组，将新的地址赋值给arr3
        arr3=new int[]{1,2,3,4};


    }


}
